

<?php

include ("includes/connection.php");
include ("./includes/iniciaSessio.php");
include ("./includes/funcions.php");

/*function conveteixData($data) {
	$dataC = explode("-", $data);
	return $dataC[2] . "-" . $data[1] . "-" . $data[0];
	
}*/

if (isset($_SESSION["username"])) {
$auxRec=$_POST['enviar'];
	//var_dump($auxRec);
	
		$latOrigen=$auxRec[0][0];
		$lngOrigen=$auxRec[0][1];
		$origen = $auxRec[0][2];
	
		$latDesti=$auxRec[1][0];
		$lngDesti=$auxRec[1][1];
		$desti = $auxRec[1][2];
	

	$sqlExisteix="select * from ruta where adresaOrigen='$origen' and adresaFinal='$desti'";
	
	$result=mysql_query($sqlExisteix,$conexion)or die(mysql_error());
	
	$totEmp = mysql_num_rows($result);
	//echo $totEmp;
	if ($totEmp ==0) {
	
		$sql="INSERT INTO `sintesi`.`ruta` (`idRuta`, `adresaOrigen`, `adresaFinal`, `Xi`, `Yi`, `Xf`, `Yf`, `comentaris`)VALUES (NULL, '$origen', '$desti', $latOrigen, $lngOrigen,$latDesti,$lngDesti, NULL);";
	
	if ((mysql_query($sql, $conexion))) {
		
		
		//echo "hola";
	}
	}
	
	
}


?>